package com.nacos.temp1.support;

import org.springframework.cloud.client.ServiceInstance;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

@Component
public class RotationLoadBalance implements LoadBalancer {

    private AtomicInteger atomicCounter = new AtomicInteger(0);

    @Override
    public ServiceInstance getSelected(List<ServiceInstance> serviceInstanceList) {
        int modulusValue = atomicCounter.incrementAndGet() % serviceInstanceList.size();
        return serviceInstanceList.get(modulusValue);
    }

}
